package com.example.library_base.router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor

@Interceptor(priority = 1)
class RouterInterceptor: IInterceptor{
    override fun init(context: Context) {

    }

    override fun process(postcard: Postcard, callback: InterceptorCallback) {
        val isLogin = true
        if (isLogin){
            //已经登录不拦截
            callback.onContinue(postcard)
        }else{
            when(postcard.path){
                //不需要登录的页面
                WeatherRouterPath.WEATHER_MAIN,
                WeatherRouterPath.WEATHER_TITLE->{
                    callback.onContinue(postcard)
                }
                else->{
                    //默认需要登录
                    callback.onInterrupt(null)
                }
            }
        }
    }
}